package com.jugheadzhou.influxdb2test.config;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.jugheadzhou.influxdb2test.manager.IcuCollectBucketApiManager;
import com.jugheadzhou.influxdb2test.manager.RequestTotalBucketApiManager;
import com.jugheadzhou.influxdb2test.properties.InfluxDB2Properties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(InfluxDB2Properties.class)
public class InfluxDB2Config {

    @Bean
    public InfluxDBClient influx2Client(InfluxDB2Properties properties) {
        return InfluxDBClientFactory.create(properties.getUrl(), properties.getToken().toCharArray(), properties.getOrg());
    }

    @Bean
    public IcuCollectBucketApiManager icuCollectBucketApiManager(InfluxDBClient influx2Client, InfluxDB2Properties properties) {
        return new IcuCollectBucketApiManager(
                influx2Client,
                properties.getOrg(),
                "aegle_icu_collect_bucket",
                "icu_collect_temperature"
        );
    }

    @Bean
    public RequestTotalBucketApiManager requestTotalBucketApiManager(InfluxDBClient influx2Client, InfluxDB2Properties properties) {
        return new RequestTotalBucketApiManager(
                influx2Client,
                properties.getOrg(),
                "influxdb2_service_api_call",
                "api_call_record"
        );
    }
}
